/*
 * @Date: 2023-10-21 20:11:28
 * @LastEditTime: 2023-10-24 00:18:25
 * 介绍:
 */
/**
 * 切换显示
 * @param config
 * @returns
 */
export function useShow(config?: UseShowConfig) {
  const show = ref(!!config?.show);
  let timeout: NodeJS.Timeout | null = null;
  function close() {
    show.value = false;
    if (timeout) clearTimeout(timeout);
  }
  function open() {
    if (timeout) clearTimeout(timeout);
    show.value = true;
    if (config?.autoClose === false) return;
    timeout = setTimeout(close, config?.closeTimeout || 5000);
  }
  function switchShow() {
    if (show.value) return close();
    open();
  }
  return { show, open, close, switchShow };
}

export interface UseShowConfig {
  /**是否自动关闭 */
  autoClose?: boolean;
  show?: boolean;
  /**自动隐藏触发时间，默认3000 */
  closeTimeout?: number;
}
